package com.mjk.imports;

import com.mjk.api.dto.ApiDto;
import com.mjk.common.base.error.BeeError;
import com.mjk.common.base.response.BeeResponse;
import com.mjk.common.base.work.BaseWork;
import com.mjk.common.base.work.annotation.BeeWork;
import com.mjk.common.core.jdbc.service.plus.idbservice.BeeDBService;
import com.mjk.common.tools.excel.type.FileType;
import com.mjk.common.tools.gson.GsonUtils;
import com.mjk.datasource.model.MiProperties;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.*;
import java.util.List;

/**
 * 物料导入功能
 */
@BeeWork(work = "import")
public class ImportWork extends BaseWork {

    @Autowired
    private BeeDBService beeDBService;

    public BeeResponse importTest(ApiDto dto){
        try (InputStream is = new ByteArrayInputStream(dto.getContext().getBytes(dto.getEncode()))){
            List<MiProperties> list = FileType.getFileImportAndExport(dto.getFileType()).importFile(MiProperties.class, is, dto.getEncode());
            System.out.println(GsonUtils.bean2Json(list));
            return BeeError.BEE_SUC.tranceError();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


}
